﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Resource : IAccessible<P_Resource, Resource>, ILogicEntity<P_Resource, Resource>
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public ResourceType Type { get; set; }
        public ResourceSubType SubType { get; set; }
        public int RefId { get; set; }
        public PrivateLevel PrivateLevel { get; set; }
        public string Path { get; set; }
        public string ExtendName { get; set; }
        public string FileSize { get; set; }
        public DateTime CreateTime { get; set; }
        public string CreateUser { get; set; }

        protected override void Covariant(P_Resource model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.CreateUser = model.CreateUser;
                this.ExtendName = model.ExtendName;
                this.FileSize = model.FileSize;
                this.ID = model.ID;
                this.Name = model.Name;
                this.Path = model.Path;
                this.PrivateLevel = (PrivateLevel)model.PrivateLevel;
                this.RefId = model.RefId;
                this.Type = (ResourceType)model.Type;
                this.SubType = (ResourceSubType)model.SubType;
            }
        }

        protected override P_Resource Inverter(Resource model)
        {
            if (model != null)
            {
                return new P_Resource()
                {
                    CreateTime = model.CreateTime,
                    CreateUser = model.CreateUser,
                    ExtendName = model.ExtendName,
                    FileSize = model.FileSize,
                    ID = model.ID,
                    Name = model.Name,
                    Path = model.Path,
                    PrivateLevel = (int)model.PrivateLevel,
                    RefId = model.RefId,
                    Type = (int)model.Type,
                    SubType = (int)model.SubType
                };
            }
            return null;
        }

        public Resource Set(P_Resource dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
